package com.ruanyin.web.servlet;

import com.ruanyin.domain.PageBean;
import com.ruanyin.domain.User;
import com.ruanyin.service.UserService;
import com.ruanyin.service.impl.UserServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/findUserByPageServlet")
public class FindUserByPageServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取参数，
        String currentPage = request.getParameter("currentPage");
        String rows = request.getParameter("rows");

        // 调用service查询PageBean
        UserService service = new UserServiceImpl();
        PageBean<User> pageBean = service.findUserByPage(currentPage, rows);

        // 将pagebean存入request
        request.setAttribute("pb", pageBean);

        // forward
        request.getRequestDispatcher("/list.jsp").forward(request, response);
    }
}
